<?php
/**
 *	KLF Framework
 *
 *	Written by Kristian Oye <kristianoye@gmail.com> on Dec 19, 2011
 *	Copyright (C) 2010-2011
 */
namespace KLF\System\Web\MVC
{
	use KLF\System\KObject;

	/**
	 *  Class KActionInvoker
	 *
	 *  Contains a wrapper around an action method with an argument list.
	 *
	 *  @package KLF\System\Web\MVC
	 *  @access public
	 *  @author Kristian Oye <kristianoye@gmail.com>
	 *  @since 0.1
	 *
	 *  @method KActionInvoker NewInstance
	 *  
	 *  @property array $Arguments
	 *  @property KController $Controller
	 *  @property \ReflectionMethod $Method
	 */
	class KActionInvoker extends KObject implements IActionInvoker
	{
		/**
		 * Parameters to pass into the action.
		 * 
		 * @var array $_rpropArguments
		 */
		protected $_rpropArguments;
		
		/**
		 * The controller in which the action resides.
		 * 
		 * @var KController $_rpropController
		 */
		protected $_rpropController;
		
		/**
		 * 
		 * Enter description here ...
		 * @var unknown_type
		 */
		protected $_rpropMethod;
		
		public function __construct($method, $instance, $args)
		{
			$this->_rpropArguments = $args;
			$this->_rpropController = $instance;
			$this->_rpropMethod = $method;
		}
		
		public function InvokeAction(KControllerContext $context, $actionName)
		{
			/* @var $method \ReflectionMethod */
			$args = $this->_rpropArguments;
			$method = $this->_rpropMethod;
			$controller = $this->_rpropController;
			
			$method->invokeArgs($controller, $args);
		}
	}
}